/**
 * @author gao
 * @date 2025/6/23 12:42
 */

public class Demo1 {
    public static void main(String[] args) {
        // 创建线程对象
        Thread t1 = new Thread() {
            @Override
            public void run() {
                while (true) {
                    System.out.println("hello t1");
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        };
        t1.start();

        // 使用Runnable对象创建线程
        Thread t2 = new Thread(new Runnable() {
            @Override
            public void run() {
                while (true) {
                    System.out.println("hello t2");
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        });
        t2.start();

        // 创建线程对象并使用name参数命名
        Thread t3 = new Thread("这是我的t3线程") {
            @Override
            public void run() {
                while (true) {
                    System.out.println("hello t3");
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        };
        t3.start();

        // 使用Runnable对象创建线程并使用name参数命名
        Thread t4 = new Thread(new Runnable() {
            @Override
            public void run() {
                while (true) {
                    System.out.println("hello t4");
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        }, "这是我的t4线程");
        t4.start();

        /*while (true) {
            System.out.println("hello main");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }*/
    }
}